#include <stdio.h>

int like[5][5]={{0,0,1,1,0},
                {1,1,0,0,1},
                {0,1,1,0,1},
                {0,0,0,1,0},
                {0,1,0,0,1}};
int book[5]={0};
int person[5]={0};
int sun=0;

void selve(int n)
{

   if(n==5)
   {
       sun++;
       printf("num = %d: ",sun);
       for(int i=0;i<5;i++)
       {
           printf("%d ",person[i]);
       }
       printf("\n");
   }
   else {
       for (int j=0; j< 5; j++) {
           if (like[n][j] == 1 && book[j] == 0) {
               person[n]=j;
               book[j]=1;
               selve(n+1);
               book[j]=0;
               person[n]=0;
           }
       }
   }
}

int main(void) {
    selve(0);
    return 0;
}
